/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GUI;
import config.*;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author RYUDO
 */
public class Splash extends JFrame{
    JLabel loadStatus;
    public Splash() throws InterruptedException {
        this.initComponents();

    }

    /** Function to initialize all the components **/
    private void initComponents() throws InterruptedException {
        int w = 460;
        int h = 310;
        setSize(w,h);
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        int x = (screen.width-w)/2;
        int y = (screen.height-h)/2;
        setBounds(x, y, w, h);
        setTitle("Loading...");
       

        /** Creating the loading splash screen **/
        JLayeredPane container = getLayeredPane();
        JLabel background = new JLabel(new ImageIcon(getClass().getResource("/image/Splash.png")));
        background.setBorder(BorderFactory.createEtchedBorder());
        background.setBounds(0, 0, w, h);
        loadStatus = new JLabel("Loading...checking database");
        loadStatus.setBounds(10,285,w,20);
        container.add(background,new Integer(1));
        container.add(loadStatus,new Integer(2));

        this.setUndecorated(true);
        this.setVisible(true);
        Function.loadEffect();
        this.loadStatus.setText("Establishing Database Connection ...");
        if(!Function.check_connection_file()) {
            DatabaseConnector dc = new DatabaseConnector();
            dc.setVisible(true);
            this.dispose();
        } else {
            Staff_login sl = new Staff_login();
            this.loadStatus.setText("Loading Main Login ...");
            sl.setVisible(true);
            this.dispose();
        }
       
    }
    public static void main(String[] args) throws InterruptedException {
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
            Splash init_splash = new Splash();
            
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Splash.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(Splash.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(Splash.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(Splash.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    
}
